<?php
/**
 * 轻云网络验证系统
 * =======================================================
 * 版权所有(C) 2019-2039 daenx.cn，并保留所有权利。
 * 作者：Daen大恩
 * 作者QQ: 1330166565
 * 开发群：661059773
 * =======================================================
 */
    include 'farmwork.php';
	header("content-type:text/html;charset=utf-8");
	login();
	
	$id = $_GET['id'];
	$sql = "SELECT * FROM `authorize` WHERE id ='$id';";
	$result=mysqli_query($con,$sql);
	if($result&&mysqli_num_rows($result)){
	   while ($row=mysqli_fetch_assoc($result)) {
			  $username = $row['username'];
			  $domain = $row['domain'];
			  $qq = $row['qq'];
			  $rmb = $row['rmb'];
			  if($rmb==null){$rmb=0;}
			  $version = $row['version'];
			  $syskey = $row['syskey'];
			  $yumi = $row['yumi'];
			  $ycp = $row['ycp'];
			  $pass = $row['pass'];
			  $timegl = $row['time'];
			  $timeg2 = $row['time'];
			  $dl = $row['dl'];
			  $bz = $row['bz'];
	   }
	}	

	
	$action = $_GET['action'];
	if($action=='do'){
		$id = $_POST['id'];
		$username = $_POST['username'];
		$domain = $_POST['domain'];
		$qq = $_POST['qq'];
		$rmb = $_POST['rmb'];
		$syskey = $_POST['syskey'];
		$yumi = $_POST['yumi'];
		$ycp = $_POST['ycp'];
		$pass = $_POST['pass'];
		$dl = $_POST['dl'];
		$bz = $_POST['bz'];
		if($_POST['leixing']=='free')
		{$time ="free";}
	else{
	$time = strtotime($_POST['time']);}
		$sql = "UPDATE `authorize` SET `username` = '$username', `domain` = '$domain',`pass` = '$pass',`qq` = '$qq',`time` = '$time',`syskey` = '$syskey',`yumi` = '$yumi',`ycp` = '$ycp',`rmb` = '$rmb',`dl` = '$dl',`bz` = '$bz' WHERE `id` = '$id';";
	    mysqli_query($con,$sql);
		//mysqli_close();
		echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">更新成功！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'authorize.php' });  }});</script>");
	}

$li1='class="active"';
$li10='class="active"';
?>
<?php include 'header.php';?>
    <title>更新授权-<?php echo $title?></title>
<?php include 'list.php';?>
    <!--main content start-->
    <section id="main-content">
        <section class="wrapper">
<?php include 'overview.php';?>
            <div class="row">
                <div class="col-lg-12">
                    <!--work progress start-->
                    <section class="panel">
                        <div class="panel-body progress-panel">
                            <div class="task-progress">
                                <h1>更新授权</h1>
                                <p>填写新的授权信息并保存.</p>
                            </div>
                        </div>						
                         <form action="authorize-chanage.php?action=do" method="post"  role="form">
                            
                            <div class="form-group">
                                <label for="txtDomain">产品</label>
                                <select name="ycp" class="form-control" >
								<option ><?php echo $ycp?></option>
 									<?php 
										$sql="select * from products ORDER BY `id` DESC";
										$result=mysqli_query($con,$sql);
										if($result&&mysqli_num_rows($result)){
											while ($row=mysqli_fetch_assoc($result)) {
											echo "<option value='".$row['cp']."'>".$row['cp']."</option>";											
											}
										}
									?>   
									</select>
                            </div>
							<div class="form-group">
                                <label for="txtDomain">用户名</label>
                                <input type="text" name="username" class="form-control" value='<?php echo $username?>' required/>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain">账号</label>
                                <input type="text" name="domain" class="form-control" value='<?php echo $domain?>' required/>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain">密码</label>
                                <input type="text" name="pass" class="form-control" value='<?php echo $pass?>' required/>
                            </div>
							<div class="form-group">
							  <label>会员</label>
							  <select name="dl" class="form-control">
							  <option ><?php echo $dl?></option>
							  <option value="普通用户">普通用户</option>
								<option value="VIP1">VIP1</option>
								<option value="VIP2">VIP2</option>
								<option value="VIP3">VIP3</option>
								<option value="VIP4">VIP4</option>
								<option value="VIP5">VIP5</option>
								<option value="VIP6">VIP6</option>
								<option value="VIP7">VIP7</option>
								<option value="VIP8">VIP8</option>
							  </select>
							</div>
                            <div class="form-group">
                                <label for="txtDomain">联系人QQ</label>
                                <input type="text" name="qq" class="form-control" value='<?php echo $qq?>' required/>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain">余额</label>
                                <input type="text" name="rmb" class="form-control" value='<?php echo $rmb?>' required/>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain"><i class="fa fa-key"></i>用户KEY<input class="btn btn-primary btn-xs" type= "button" name= "Submit1 " value= "生成" onclick= "show()"></label>
                                <input type="text" name="syskey" id="syskey"  class="form-control" value='<?php echo $syskey?>' required/>
 					<script language=javascript> 
						function show() 
						{ 
						var str= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 
						var result= " " 
						for(var i=0;i <32;i++) 
						{ 
						var temp=Math.floor(Math.random()*36) 
						result+=str.charAt(temp) 
						} 
						hash = result.MD5();
						document.getElementById( "syskey").value=hash
						} 
					</script>
                            </div>
                            
							
                            <div class="form-group">
                                <label for="txtDomain">状态</label>
                                <select name="yumi" class="form-control">
                                            
											<?php if($yumi == 1)
											{echo '<option value="0">正常</option>
                                            <option value="1" selected>禁用</option>';}
											else 
											{echo '<option value="0" selected>正常</option>
                                            <option value="1">禁用</option>';}
											?>
											
                                            
                                           
                                        </select>
								<span class="help-block">当前状态：<?php if($yumi==1){ echo "<font color='red'>禁用中</font>";} else {echo "<font color='red'>正常</font>";} ?></span>
																			
                            </div>
							
							<div class="form-group">
                                <label for="txtDomain">类型</label>
                                <select name="leixing" class="form-control">
                                            <?php if($timeg2 == "free")
											{echo '<option value="free" selected>免费用户</option>
                                            <option value="nofree" >收费用户</option>';}
											else 
											{echo '<option value="free">免费用户</option>
                                            <option value="nofree" selected>收费用户</option>';}
											?>
											

                                        </select>
								<span class="help-block">当前状态：<?php if($timeg2 == "free"){echo "<font color='red'>免费用户</font>";}else {echo "<font color='red'>收费用户</font>";} ?></span>
																			
                            </div>
							
                            <div class="form-group">
                                <label for="txtDomain">到期时间(留空则永久)</label>
                                <input type="text" name="time" class="form-control" id="time1" value='<?php 
								if($timegl == null)
								{echo "永久";}
							else{
							echo date("Y-m-d",$timegl);}?>'>
                            </div>
							
							<div class="form-group">
								<label for="txtDomain">备注</label>
								<input type="text" name="bz" class="form-control" value='<?php echo $bz?>'/>
							</div>
							<input type='hidden' name="id" class="user" value='<?php echo $id?>'/>
			<div id="bottom">
			  <button class="btn btn-info" type="submit" value="true" id="submit"/><strong>更新授权</strong></button>
            </div>
                        </form>
                    </section>
                    <!--work progress end-->
                </div>

        </section>
    </section>
    <!--main content end-->

<?php
 include 'footer.php';?>